home *** CD-ROM | disk | FTP | other *** search
- // das.cpp file to test dice.lib, math.lib,
- // and util.lib function libraries
- #include <conio.h>
- #include <iostream.h>
- #include <stdlib.h>
- #include <time.h>
-
- // math.lib
- long square(long);
- long cube(long);
- void count_up(long);
- void count_down(long);
- void compound_int(double,double,int);
- long fibonacci(long);
- long minimum(long,long,long);
- long maximum(long,long,long);
- long iterative_fact(long);
- long recursive_fact(long);
- // dice.lib
- int one_die(int,int,int,char[]);
- int two_dice(int,int,int,int,char[]);
- // util.lib
- void line_draw(void);
- void swap_p(int *,int *);
- void swap_r(int&,int&);
-
- void main()
- {// begin demo
- TOP:
-
- int num1,num2;
- long a,b,c,d,e,numb,res;
- double principal,rate;
- randomize();
-
- // demonstrate minimum()
- cout<<"\nMinimum number";
- line_draw();
- cout<<"Enter three numbers: ";
- cin>>a>>b>>c;
- cout<<"Minimum is "<<minimum(a,b,c)<<"\n";
-
- // demonstrate maximum()
- cout<<"Maximum number";
- line_draw();
- cout<<"Enter three numbers: ";
- cin>>a>>b>>c;
- cout<<"Maximum is "<<maximum(a,b,c)<<"\n";
-
- // demonstrate count_up()
- cout<<"Count up numbers";
- line_draw();
- cout<<"Enter a number: ";
- cin>>c;
- count_up(c);
-
- // demonstrate count_down()
- cout<<"Count down numbers";
- line_draw();
- cout<<"Enter a number: ";
- cin>>c;
- count_down(c);
-
- // demonstrate cube()
- cout<<"Cube a number";
- line_draw();
- cout<<"Enter a number: ";
- cin>>c;
- cout<<"Cube of "<<c<<" is "<<cube(c)<<"\n";
-
- // demonstrate square()
- cout<<"Square a number";
- line_draw();
- cout<<"Enter a number: ";
- cin>>c;
- cout<<"Square of "<<c<<" is "<<square(c)<<"\n";
-
- // demonstrate compound_int()
- cout<<"Calculate Compound Interest";
- line_draw();
- cout<<"Enter the principal: ";
- cin>>principal;
- cout<<"Enter the rate: ";
- cin>>rate;
- cout<<"Enter the years: ";
- cin>>num1;
- cout<<" Year Amount on deposit\n";
- compound_int(principal,rate,num1);
-
- // demonstrate one_die()
- cout<<"Computer 1 Die Throw";
- line_draw();
- cout<<"Enter size of die: ";
- cin>>num1;
- cout<<"Enter delay for roll: ";
- cin>>num2;
- for (d=1;d<=10;d++){
- one_die(num1,num2,1,"One die: ");
- cout<<"\n";
- }
-
- // demonstrate two_dice()
- cout<<"Computer 2 Dice Throw / Sum";
- line_draw();
- cout<<"Enter size of dice: ";
- cin>>num1;
- cout<<"Enter delay for roll: ";
- cin>>num2;
- for (d=1;d<=10;d++){
- two_dice(num1,num2,1,1,"Two dice: ");
- cout<<"\n";
- }
-
- // demonstrate i_factorial() - iterative version
- cout<<"Iterative Factorial";
- line_draw();
- cout<<"Enter a number: ";
- cin>>e;
- cout<<e<<"! is "<<iterative_fact(e)<<"\n";
-
- // demonstrate r_factorial() - recursive version
- cout<<"Recursive Factorial";
- line_draw();
- cout<<"Enter a number: ";
- cin>>e;
- cout<<e<<"! is "<<recursive_fact(e)<<"\n";
-
- // demonstrate fibonacci()
- cout<<"Fibonacci numbers";
- line_draw();
- cout<<"Enter a number: ";
- cin>>numb;
- res = fibonacci(numb);
- cout<<"Fibonacci("<<numb<<") = "<<res<<"\n";
-
- // demonstrate swap_p()
- cout<<"Swap with pointers";
- line_draw();
- cout<<"Enter two numbers: ";
- cin>>num1>>num2;
- cout<<"Numbers are "<<num1<<" and "<<num2<<"\n";
- swap_p(&num1,&num2);
- cout<<"Swapped numbers are "<<num1<<" and "<<num2<<"\n";
-
- // demonstrate swap_r()
- cout<<"Swap with call by reference";
- line_draw();
- cout<<"Enter two numbers: ";
- cin>>num1>>num2;
- cout<<"Numbers are "<<num1<<" and "<<num2<<"\n";
- swap_r(num1,num2);
- cout<<"Swapped numbers are "<<num1<<" and "<<num2<<"\n";
-
- cout<<"Run demo again (y/n) ? ";
- if (getche()=='y') goto TOP;
-
- }// end demo
-
-